////
////  ZJCycleScrollView.swift
////  健身宝
////
////  Created by hzt on 2017/10/25.
////  Copyright © 2017年 hzt. All rights reserved.
////
//
//import UIKit
//
//
//let sectionNum: Int = 100
//let cellIdentifier: String = "cellIdentifier"
//let width = (UIScreen.main.bounds.size.width)
//let height = (UIScreen.main.bounds.size.width)
//// 协议
//protocol ZJCycleViewDelegate {
//    func didSelectIndexCollectionViewCell(index: Int)->Void
//}
//
//class ZJCycleScrollView: UIView, UICollectionViewDelegate, UICollectionViewDataSource{
//    
//    /*
//     // Only override drawRect: if you perform custom drawing.
//     // An empty implementation adversely affects performance during animation.
//     override func drawRect(rect: CGRect) {
//     // Drawing code
//     }
//     */
//    var delegate: ZJCycleViewDelegate?
//    var cycleCollectionView: UICollectionView?
//    var images = NSMutableArray()
//    var pageControl = UIPageControl()
//    var flowlayout = UICollectionViewFlowLayout()
//    var timer = Timer()
//    override init(frame: CGRect) {
//        super.init(frame: frame)
//        self.createSubviews(frame: frame)
//    }
//    
//    required init?(coder aDecoder: NSCoder) {
//        fatalError("init(coder:) has not been implemented")
//    }
//    // 创建collectionview
//    func createSubviews(frame: CGRect){
//        cycleCollectionView = UICollectionView.init(frame: CGRectMake(0, 0, frame.size.width, frame.size.height), collectionViewLayout: flowlayout)
//        flowlayout.itemSize = CGSizeMake(frame.size.width, frame.size.height);
//        flowlayout.minimumInteritemSpacing = 0;
//        flowlayout.minimumLineSpacing = 0;
//        flowlayout.scrollDirection = UICollectionViewScrollDirection.horizontal;
//        
//        cycleCollectionView!.backgroundColor = UIColor.lightGray
//        cycleCollectionView!.isPagingEnabled = true
//        cycleCollectionView!.dataSource  = self
//        cycleCollectionView!.delegate = self
//        cycleCollectionView!.showsHorizontalScrollIndicator = false
//        cycleCollectionView!.showsVerticalScrollIndicator = false
//        cycleCollectionView!.register(ZJCustomCycleCell.self, forCellWithReuseIdentifier: cellIdentifier)
//        self.addSubview(cycleCollectionView!)
//        
//        pageControl = UIPageControl.init(frame: CGRectMake(0, 0, frame.size.width / 2, 30))
//        pageControl.center = CGPointMake(frame.size.width / 2, frame.size.height - 20);
//        self.addSubview(pageControl);
//        self.addTimer()
//        
//    }
//    func addTimer(){
//        let timer1 = Timer.init(timeInterval: 2, target: self, selector: "nextPageView", userInfo: nil, repeats: true)
//        RunLoop.current.add(timer1, forMode: RunLoopMode.commonModes)
//        timer = timer1
//    }
//    func removeTimer(){
//        self.timer.invalidate()
//    }
//    func returnIndexPath()->NSIndexPath{
//        var currentIndexPath = cycleCollectionView!.indexPathsForVisibleItems.last
//        currentIndexPath = NSIndexPath.init(forRow: (currentIndexPath?.row)!, inSection: sectionNum / 2)
//        cycleCollectionView!.scrollToItem(at: currentIndexPath!, at: UICollectionViewScrollPosition.left, animated: false)
//        return currentIndexPath! as NSIndexPath;
//    }
//    func nextPageView(){
//        
//        let indexPath = self.returnIndexPath()
//        var item = indexPath.row + 1;
//        var section = indexPath.section;
//        if item == images.count {
//            item = 0
//            section += 1
//        }
//        self.pageControl.currentPage = item;
//        let nextIndexPath = NSIndexPath.init(forRow: item, inSection: section)
//        cycleCollectionView!.scrollToItemAtIndexPath(nextIndexPath, atScrollPosition: UICollectionViewScrollPosition.Left, animated: true)
//    }
//    // Delegate
//    func collectionView(_ cellForItemAtcollectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
//        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellIdentifier, forIndexPath: indexPath) as! ZJCustomCycleCell
//        cell.labelTitle.text = NSString(format: "%d", indexPath.row) as String
//        let url:String = self.images[indexPath.row] as! String
//        cell.imageView.hnk_setImageFromURL(NSURL.init(string: url)!)
//        return cell
//    }
//    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
//        return sectionNum
//    }
//    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
//        pageControl.numberOfPages = images.count
//        return images.count
//    }
//    func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) {
//        self.addTimer()
//    }
//    func scrollViewWillBeginDragging(scrollView: UIScrollView) {
//        self.removeTimer()
//    }
//    func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
//        let page = (Int(scrollView.contentOffset.x) / Int(width)) % images.count
//        pageControl.currentPage = page
//    }
//    // 点击
//    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
//        //
//        self.delegate?.didSelectIndexCollectionViewCell(index: indexPath.row)
//    }
//}
//
